﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Timers;
using System.Threading;
using MvcApplicationYoung.Models;

namespace MvcApplicationYoung.WcfServiceLibrary
{
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.PerSession)]
    public class Service1 : IService1
    {
        MyDBDirect dbDirectAdapter;
        MyDBEnts dbAdapter;

        public Service1()
        {
            dbAdapter = new MyDBEnts();
            dbDirectAdapter = new MyDBDirect();
        }

        public bool CheckUser(string usr, string pwd)
        {
            if (dbDirectAdapter.CheckUser(usr, pwd))
            {
                //EventConnectionComming.Invoke(string.Format("new connection comming: {0} | {1}", usr, pwd));   
                return true;
            }

         return false;
        }

        public string GetMenuesXMLJson()
        {

            return dbAdapter.GetMenuesXMLJson();
//            return "test:GetMenuesXMLJson";
        }

        public string GetTableJson(string objectID, string objectType)
        {
            if (Enum.IsDefined(typeof(MyDBEnts.SingleTable), objectType))
            {
                return dbAdapter.GetTableJson(objectID, (MyDBEnts.SingleTable)Enum.Parse(typeof(MyDBEnts.SingleTable), objectType));
            }
            else
            {
                return "";
            }
        }

        public string UpdateEmployeeRow(string commitType,string modifyEmployeeRow)
        {
            return dbAdapter.UpdateEmployeeRow(commitType,modifyEmployeeRow);
        }

        public string UpdateDepartmentRow(string commitType, string modifyDepartmentRow)
        {
            return dbAdapter.UpdateDepartmentRow(commitType, modifyDepartmentRow);
        }
    }

}
